<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>BrokenIRC: server_src/commands_parsing.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">BrokenIRC
   &#160;<span id="projectnumber">0.0.42</span>
   </div>
   <div id="projectbrief">A &#39;not so functionnal&#39; irc server and a WIP client</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_20e5c1c74b8b955148e6b35ac4a0bc4d.html">server_src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">commands_parsing.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="commands__parsing_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">** EPITECH PROJECT, 2018</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">** MY_IRC</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">** File description:</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">** my_irc server commands parsing functions source file</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">*/</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &quot;../include/server.h&quot;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno"><a class="line" href="commands__parsing_8c.html#a9bf380b201748032988ca121dc4ed068">   14</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="commands__parsing_8c.html#a9bf380b201748032988ca121dc4ed068">free_buffers</a>(<span class="keywordtype">char</span> **buffer)</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;{</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;        <span class="keywordtype">int</span> i;</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;        <span class="keywordflow">for</span> (i = 0; buffer[i]; ++i) {</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;                free(buffer[i]);</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        }</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;        free(buffer);</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;}</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00028"></a><span class="lineno"><a class="line" href="commands__parsing_8c.html#ae88af3c7c8c827d710efa585d851a414">   28</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">char</span>     **<a class="code" href="commands__parsing_8c.html#ae88af3c7c8c827d710efa585d851a414">get_commands</a>(<span class="keywordtype">char</span> *req)</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;{</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;        <span class="keywordtype">int</span> i = 0;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        <span class="keywordtype">char</span> *cmd = NULL;</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        <span class="keywordtype">char</span> **<a class="code" href="server_8h.html#abc9c1e6f561b7500f7ecb3813d272d20">cmds</a> = malloc(<a class="code" href="server_8h.html#a41101847771d39a4f0a7f9395061c629">MAXARGS</a> * <span class="keyword">sizeof</span>(*cmds));</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <span class="keywordflow">if</span> (cmds) {</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;                memset(cmds, 0, <span class="keyword">sizeof</span>(*cmds) * <a class="code" href="server_8h.html#a41101847771d39a4f0a7f9395061c629">MAXARGS</a>);</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;                cmd = strtok(req, <span class="stringliteral">&quot;\r\n&quot;</span>);</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;                <span class="keywordflow">while</span> (cmd) {</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;                        cmds[i] = strdup(cmd);</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;                        cmd = strtok(NULL, <span class="stringliteral">&quot;\r\n&quot;</span>);</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;                        i = i &lt;= MAXARGS ? i + 1 : i;</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;                }</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        }</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <span class="keywordflow">return</span> (cmds);</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;}</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="commands__parsing_8c.html#ad7cc037b9642ffd85e521546772eceae">   49</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">char</span>     **<a class="code" href="commands__parsing_8c.html#ad7cc037b9642ffd85e521546772eceae">get_args</a>(<span class="keywordtype">char</span> *cmd)</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;{</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        <span class="keywordtype">int</span> i = 0;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        <span class="keywordtype">char</span> *token = NULL;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        <span class="keywordtype">char</span> **tkns = malloc(<a class="code" href="server_8h.html#a41101847771d39a4f0a7f9395061c629">MAXARGS</a> * <span class="keyword">sizeof</span>(*tkns));</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        <span class="keywordflow">if</span> (tkns) {</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;                memset(tkns, 0, <span class="keyword">sizeof</span>(*tkns) * <a class="code" href="server_8h.html#a41101847771d39a4f0a7f9395061c629">MAXARGS</a>);</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;                token = strtok(cmd, <span class="stringliteral">&quot; :&quot;</span>);</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;                <span class="keywordflow">while</span> (token) {</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;                        tkns[i] = strdup(token);</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;                        token = strtok(NULL, <span class="stringliteral">&quot; :&quot;</span>);</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;                        i = i &lt;= MAXARGS ? i + 1 : i;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;                }</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;        }</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        <span class="keywordflow">return</span> (tkns);</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;}</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="server_8h.html#ac5949d17278df5e1ada98dca25ccd961">   73</a></span>&#160;<span class="keywordtype">int</span>     <a class="code" href="commands__parsing_8c.html#ac5949d17278df5e1ada98dca25ccd961">get_methods</a>(<span class="keywordtype">char</span> *req, <span class="keywordtype">int</span> clifd)</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;{</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;        <span class="keywordtype">int</span> index = 0;</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;        <span class="keywordtype">char</span> **<a class="code" href="server_8h.html#abc9c1e6f561b7500f7ecb3813d272d20">cmds</a> = <a class="code" href="commands__parsing_8c.html#ae88af3c7c8c827d710efa585d851a414">get_commands</a>(req);</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;        <span class="keywordtype">char</span> **args = NULL;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <span class="keyword">static</span> <a class="code" href="structt__channel.html">t_channel</a> *defchan = NULL;</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        defchan = !defchan ? <a class="code" href="channel__list_8c.html#a1c3fc93845d179d198452e745f3460b1">init_default_channel</a>() : defchan;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; cmds[j]; ++j) {</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;                <span class="keywordflow">for</span> (index = 0; <a class="code" href="server__decls_8c.html#ae19e01ff7678899828036520edec313c">G_PROTOS</a>[index]; ++index) {</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;                        <span class="keywordflow">if</span> ((strstr(cmds[j], <a class="code" href="server__decls_8c.html#ae19e01ff7678899828036520edec313c">G_PROTOS</a>[index]))) {</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;                                args = <a class="code" href="commands__parsing_8c.html#ad7cc037b9642ffd85e521546772eceae">get_args</a>(cmds[j]);</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;                                <a class="code" href="server__decls_8c.html#a7bb29231b69e3767e187ffe5d5717b28">G_CMDS</a>[index](args, clifd, defchan);</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;                                <a class="code" href="commands__parsing_8c.html#a9bf380b201748032988ca121dc4ed068">free_buffers</a>(args);</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;                                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;                        }</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;                }</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;        }</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;        <a class="code" href="logs__helpers_8c.html#a805324e4c542079956ff84a290274d23">print_users_in_chans</a>(defchan, index);</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;        <a class="code" href="commands__parsing_8c.html#a9bf380b201748032988ca121dc4ed068">free_buffers</a>(cmds);</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        <span class="keywordflow">return</span> ((index == <a class="code" href="server_8h.html#a9880cfe1f4eb3140da2095fd081282f5">REF_NB</a>) ? (0) : (index));</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;}</div><div class="ttc" id="logs__helpers_8c_html_a805324e4c542079956ff84a290274d23"><div class="ttname"><a href="logs__helpers_8c.html#a805324e4c542079956ff84a290274d23">print_users_in_chans</a></div><div class="ttdeci">void print_users_in_chans(t_channel *chanlist, int index)</div><div class="ttdef"><b>Definition:</b> <a href="logs__helpers_8c_source.html#l00017">logs_helpers.c:17</a></div></div>
<div class="ttc" id="server__decls_8c_html_a7bb29231b69e3767e187ffe5d5717b28"><div class="ttname"><a href="server__decls_8c.html#a7bb29231b69e3767e187ffe5d5717b28">G_CMDS</a></div><div class="ttdeci">const cmds G_CMDS[REF_NB]</div><div class="ttdef"><b>Definition:</b> <a href="server__decls_8c_source.html#l00018">server_decls.c:18</a></div></div>
<div class="ttc" id="commands__parsing_8c_html_a9bf380b201748032988ca121dc4ed068"><div class="ttname"><a href="commands__parsing_8c.html#a9bf380b201748032988ca121dc4ed068">free_buffers</a></div><div class="ttdeci">static void free_buffers(char **buffer)</div><div class="ttdef"><b>Definition:</b> <a href="commands__parsing_8c_source.html#l00014">commands_parsing.c:14</a></div></div>
<div class="ttc" id="commands__parsing_8c_html_ad7cc037b9642ffd85e521546772eceae"><div class="ttname"><a href="commands__parsing_8c.html#ad7cc037b9642ffd85e521546772eceae">get_args</a></div><div class="ttdeci">static char ** get_args(char *cmd)</div><div class="ttdef"><b>Definition:</b> <a href="commands__parsing_8c_source.html#l00049">commands_parsing.c:49</a></div></div>
<div class="ttc" id="commands__parsing_8c_html_ae88af3c7c8c827d710efa585d851a414"><div class="ttname"><a href="commands__parsing_8c.html#ae88af3c7c8c827d710efa585d851a414">get_commands</a></div><div class="ttdeci">static char ** get_commands(char *req)</div><div class="ttdef"><b>Definition:</b> <a href="commands__parsing_8c_source.html#l00028">commands_parsing.c:28</a></div></div>
<div class="ttc" id="server_8h_html_a9880cfe1f4eb3140da2095fd081282f5"><div class="ttname"><a href="server_8h.html#a9880cfe1f4eb3140da2095fd081282f5">REF_NB</a></div><div class="ttdeci">#define REF_NB</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00022">server.h:22</a></div></div>
<div class="ttc" id="commands__parsing_8c_html_ac5949d17278df5e1ada98dca25ccd961"><div class="ttname"><a href="commands__parsing_8c.html#ac5949d17278df5e1ada98dca25ccd961">get_methods</a></div><div class="ttdeci">int get_methods(char *req, int clifd)</div><div class="ttdef"><b>Definition:</b> <a href="commands__parsing_8c_source.html#l00073">commands_parsing.c:73</a></div></div>
<div class="ttc" id="structt__channel_html"><div class="ttname"><a href="structt__channel.html">t_channel</a></div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00121">server.h:121</a></div></div>
<div class="ttc" id="channel__list_8c_html_a1c3fc93845d179d198452e745f3460b1"><div class="ttname"><a href="channel__list_8c.html#a1c3fc93845d179d198452e745f3460b1">init_default_channel</a></div><div class="ttdeci">t_channel * init_default_channel(void)</div><div class="ttdef"><b>Definition:</b> <a href="channel__list_8c_source.html#l00089">channel_list.c:89</a></div></div>
<div class="ttc" id="server__decls_8c_html_ae19e01ff7678899828036520edec313c"><div class="ttname"><a href="server__decls_8c.html#ae19e01ff7678899828036520edec313c">G_PROTOS</a></div><div class="ttdeci">const char * G_PROTOS[REF_NB]</div><div class="ttdef"><b>Definition:</b> <a href="server__decls_8c_source.html#l00012">server_decls.c:12</a></div></div>
<div class="ttc" id="server_8h_html_a41101847771d39a4f0a7f9395061c629"><div class="ttname"><a href="server_8h.html#a41101847771d39a4f0a7f9395061c629">MAXARGS</a></div><div class="ttdeci">#define MAXARGS</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00035">server.h:35</a></div></div>
<div class="ttc" id="server_8h_html_abc9c1e6f561b7500f7ecb3813d272d20"><div class="ttname"><a href="server_8h.html#abc9c1e6f561b7500f7ecb3813d272d20">cmds</a></div><div class="ttdeci">void *(* cmds)(cmdargs args, int clifd, t_channel *chanlist)</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00175">server.h:175</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
